define(['jquery','scrollTo'],function($,scrollTo){
  function BackTop(el,opts){
    this.opts=$.extend({},BackTop.DEFAULTS,opts);
    this.el=$(el);
    this.scroll=new scrollTo.ScrollTo({
      dest:0,
      speed:this.opts.speed
    });
    this._checkPosition();
    if(this.opts.mode=="move")
      this.el.on('click',$.proxy(function(){this._move()},this));
    else
      this.el.on('click',$.proxy(function(){this._go()},this));
    $(window).on('scroll',$.proxy(function(){this._checkPosition()},this));
  }
  BackTop.DEFAULTS={
    mode:'move',
    pos:$(window).height(),
    speed:800
  }
  BackTop.prototype._move=function(){
    this.scroll.move();
  }
  BackTop.prototype._go=function(){
    this.scroll.go();
  }
  BackTop.prototype._checkPosition=function(){
    el=this.el;
    if($(window).scrollTop()>this.opts.pos){
      el.fadeIn();
    }else {
      el.fadeOut();
    }
  }
  $.fn.extend({
    backtop:function(opts){
      return this.each(function(){
        new BackTop(this,opts)
      })
    }
  })
  return {
    BackTop:BackTop
  }
})
